<?php


/**
 * Returns a list of existing events
 */
function matchdart_events() {

  $page_content = '';

  $events = matchdart_get_events();
  
  $players = matchdart_get_players(74);
  
  print_r($events);
  
  $page_content = 'Matchdart - under heavy construction<br>';

  foreach ($events as $_event) {
    if ($_event->event == 1 AND $_event->num_matches > 0) {
    $page_content .= l($_event->name,'matchdart/table/'.$_event->tid);
    $page_content .= '&nbsp; - num_players: &nbsp;';
    $page_content .= $_event->num_players;
    $page_content .= '&nbsp; - num_matches: &nbsp;';
    $page_content .= $_event->num_matches;
    $page_content .= '&nbsp; - date_lastmatch: &nbsp;';
    $page_content .= $_event->date_lastmatch;
    $page_content .= '<br>';
    }
  }
  
  return $page_content;
  
}


/**
 * Returns a list of all events for a given taxonomy id
 *
 * Event objects contain the following fields:
 * -num_players Number of players in the event
 * -num_matches Total number of matches in the event
 * -date_lastmatch Date of most recent match for the event
 *
 * @param $tid
 *   Taxonomy ID of the event
 * @return
 *   Array of object containing the event information.
 */

/**
 * Returns a ranking table of all players for a given event (taxonomy id)
 *
 * Ranking objects contain the following fields:
 * -rank
 * -id_player Number of players in the event
 * -num_matches Total number of matches in the event
 * -last_update Most recent match for the event
 *
 * @param $tid
 *   Taxonomy ID of the event
 * @return
 *   Array of object containing the event information.
 */
function matchdart_get_ranking($tid=0) {
  
  $players = array();
  
  // get field info from cck api
  // Todo: fix $column hardcoded
  $field = content_fields('field_match_date');
  $db_info = content_database_info($field);
  $table = $db_info['table'];
  $column = 'field_match_date_value';

  
  
  
}

